|
1
|
|
|
"use strict"; |
|
2
|
|
|
|
|
3
|
|
|
app.controller('homeController', ['$scope', '$q', '$http', '$interval', '$rootScope', function ($scope, $q, $http, $interval, $rootScope) { |
|
4
|
|
|
var options = createCountUpOptions(); |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
$scope.start_milestones = function(){ |
|
7
|
|
|
$scope.milstones_interval = $interval(function(){ |
|
8
|
|
|
start_milestones($scope.stack); |
|
9
|
|
|
}, 7000) |
|
10
|
|
|
} |
|
11
|
|
|
|
|
12
|
|
|
// cancel $interval on leaving ui-state? |
|
13
|
|
|
// https://stackoverflow.com/questions/30938963/how-to-stop-interval-on-leaving-ui-state |
|
14
|
|
|
$scope.$on("$destroy",function(){ |
|
15
|
|
|
if (angular.isDefined($scope.milstones_interval)) { |
|
16
|
|
|
$interval.cancel($scope.milstones_interval); |
|
17
|
|
|
} |
|
18
|
|
|
}); |
|
19
|
|
|
|
|
20
|
|
|
$scope.get_milestones_information = function(){ |
|
21
|
|
|
$scope.initial_variable(); |
|
22
|
|
|
|
|
23
|
|
|
var getPrjectInfoResule = $scope.get_project_info(); |
|
24
|
|
|
getPrjectInfoResule.then(function(infoObj) { |
|
25
|
|
|
$scope.stack.push(infoObj); |
|
26
|
|
|
}, function(reason) { |
|
27
|
|
|
}); |
|
28
|
|
|
|
|
29
|
|
|
var getCommitInfoResule = $scope.get_github_commit_info(); |
|
30
|
|
|
getCommitInfoResule.then(function(infoObjList) { |
|
31
|
|
|
//$scope.stack.push(infoObj); |
|
32
|
|
|
$scope.stack = $scope.stack.concat(infoObjList) |
|
33
|
|
|
}, function(reason) { |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
var getReleaseInfoResule = $scope.get_github_release_info(); |
|
37
|
|
|
getReleaseInfoResule.then(function(infoObjList) { |
|
38
|
|
|
$scope.stack = $scope.stack.concat(infoObjList) |
|
39
|
|
|
}, function(reason) { |
|
40
|
|
|
}); |
|
41
|
|
|
|
|
42
|
|
|
$q.all([getPrjectInfoResule, getCommitInfoResule, getReleaseInfoResule]).then(function() { |
|
43
|
|
|
start_milestones($scope.stack); |
|
44
|
|
|
$scope.start_milestones(); |
|
45
|
|
|
}); |
|
46
|
|
|
} |
|
47
|
|
|
$scope.get_project_info = function(){ |
|
48
|
|
|
var options = createCountUpOptions(); |
|
49
|
|
|
var promise = $q(function(resolve, reject) { |
|
50
|
|
|
var array = {text:"was borned in", amt:"2015", options}; |
|
51
|
|
|
if(true){ |
|
52
|
|
|
resolve(array); |
|
53
|
|
|
}else{ |
|
54
|
|
|
reject(new Error('get project info error')); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
return promise; |
|
60
|
|
|
} |
|
61
|
|
|
$scope.get_github_commit_info = function(){ |
|
62
|
|
|
var options = createCountUpOptions(); |
|
63
|
|
|
var arrayList = []; |
|
64
|
|
|
|
|
65
|
|
|
var promise = $q(function(resolve, reject) { |
|
66
|
|
|
var array = {text:"commits", amt:"10101", options}; |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
$http({ |
|
69
|
|
|
method : "GET", |
|
70
|
|
|
url : "https://api.github.com/repos/Otaku-Projects/AngularJS-CRUD-PHP/stats/contributors" |
|
71
|
|
|
}).then(function mySuccess(response) { |
|
72
|
|
|
var returnData = response.data; |
|
73
|
|
|
var totalContributorsCount = 0; |
|
74
|
|
|
var totalCommitsCount = 0; |
|
75
|
|
|
returnData.forEach(function(contributorsObj){ |
|
76
|
|
|
totalContributorsCount+=1; |
|
77
|
|
|
totalCommitsCount+=contributorsObj.total; |
|
78
|
|
|
}); |
|
79
|
|
|
arrayList.push({text:"Contributor(s)", amt:totalContributorsCount, options}); |
|
80
|
|
|
arrayList.push({text:"Commits", amt:totalCommitsCount, options}); |
|
81
|
|
|
resolve(arrayList); |
|
82
|
|
|
}, function myError(response) { |
|
83
|
|
|
reject(new Error('get project commit info error')); |
|
84
|
|
|
}); |
|
85
|
|
|
|
|
86
|
|
|
}); |
|
87
|
|
|
|
|
88
|
|
|
return promise; |
|
89
|
|
|
} |
|
90
|
|
|
$scope.get_github_release_info = function(){ |
|
91
|
|
|
var options = createCountUpOptions(); |
|
92
|
|
|
var arrayList = []; |
|
93
|
|
|
|
|
94
|
|
|
var promise = $q(function(resolve, reject) { |
|
95
|
|
|
var array = {text:"commits", amt:"10101", options}; |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
$http({ |
|
98
|
|
|
method : "GET", |
|
99
|
|
|
url : "https://api.github.com/repos/Otaku-Projects/AngularJS-CRUD-PHP/releases" |
|
100
|
|
|
}).then(function mySuccess(response) { |
|
101
|
|
|
var returnData = response.data; |
|
102
|
|
|
var totalReleasesCount = 0; |
|
103
|
|
|
returnData.forEach(function(releasesObj){ |
|
104
|
|
|
totalReleasesCount+=1; |
|
105
|
|
|
}); |
|
106
|
|
|
|
|
107
|
|
|
if(returnData.length >0){ |
|
108
|
|
|
arrayList.push({text:"Releases Count", amt:totalReleasesCount, options}); |
|
109
|
|
|
|
|
110
|
|
|
var releasesObj = returnData[0]; |
|
111
|
|
|
|
|
112
|
|
|
var url = $('<a/>', { |
|
113
|
|
|
text: releasesObj.tag_name, |
|
114
|
|
|
href: releasesObj.html_url, |
|
115
|
|
|
target: "_blanks" |
|
116
|
|
|
}) |
|
117
|
|
|
var spanEnd = $('<span/>', { |
|
|
|
|
|
|
118
|
|
|
text: "." |
|
119
|
|
|
}) |
|
120
|
|
|
$("#latest_release").html('The latest release ver. <i class="fas fa-tag fa-fw"></i> ').append(url);//.append(spanEnd); |
|
121
|
|
|
} |
|
122
|
|
|
resolve(arrayList); |
|
123
|
|
|
}, function myError(response) { |
|
124
|
|
|
reject(new Error('get project release info error')); |
|
125
|
|
|
}); |
|
126
|
|
|
|
|
127
|
|
|
}); |
|
128
|
|
|
|
|
129
|
|
|
return promise; |
|
130
|
|
|
} |
|
131
|
|
|
$scope.initial_variable = function(){ |
|
132
|
|
|
$scope.stack = []; |
|
133
|
|
|
} |
|
134
|
|
|
function createCountUpOptions(){ |
|
135
|
|
|
var options = { |
|
136
|
|
|
startVal: 1, |
|
137
|
|
|
duration: 1, |
|
138
|
|
|
useGrouping: false, |
|
139
|
|
|
separator: ',', |
|
140
|
|
|
}; |
|
141
|
|
|
return options; |
|
142
|
|
|
} |
|
143
|
|
|
function start_milestones(stackObjectList){ |
|
144
|
|
|
$("#milestones").html(""); |
|
145
|
|
|
|
|
146
|
|
|
var infoObj = stackObjectList.shift(); |
|
147
|
|
|
var elementContent = infoObj.text; |
|
148
|
|
|
var countUpAmt = infoObj.amt; |
|
149
|
|
|
var options = infoObj.options; |
|
150
|
|
|
$("#milestones").html("<div class='animated'>"+elementContent+"</div>"); |
|
151
|
|
|
//$("#milestones div").animateCSS("fadeInUp"); |
|
152
|
|
|
$("#milestones div").addClass("fadeInUp"); |
|
153
|
|
|
|
|
154
|
|
|
//$("#count_up_amt_container").html('<span id="count_up_amt" style="display:none"></span>'); |
|
155
|
|
|
|
|
156
|
|
|
if(!$scope.countUp){ |
|
157
|
|
|
$scope.countUp = new CountUp("count_up_amt", 0, options); |
|
158
|
|
|
$scope.countUp.start(); |
|
159
|
|
|
$("#count_up_amt").hide(); |
|
160
|
|
|
} |
|
161
|
|
|
$("#count_up_amt").show(); |
|
162
|
|
|
$scope.countUp.update(countUpAmt); |
|
163
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
stackObjectList.push(infoObj); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
$scope.get_milestones_information(); |
|
169
|
|
|
}]); |
|
170
|
|
|
|
|
171
|
|
|
|